//
//  WPReadingView.m
//  wobingwoyi
//
//  Created by WGP on 16/7/26.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPReadingView.h"
#import "WPTitleView.h"
#import "WPReadingSearchBtn.h"


#define TAG_BASE 1000
//背景绿颜色
#define WPGreenColor RGB_COLOR(32, 198, 198)



@interface WPReadingView()

@property(nonatomic,strong)WPReadingSearchBtn *searchBtn;
@property(nonatomic,assign)NSInteger indexPage;

@end
@implementation WPReadingView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    self.backgroundColor = [UIColor whiteColor];
    self.indexPage = 0;
    
    self.titleView = [[WPTitleView alloc] initWithDidClickBlock:^(WPReadingTitleViewType titleBtnType) {
        
//        滑动scrollview
        CGFloat offSet = 0;
        if (titleBtnType == WPReadingTitleViewTypeIndival) {
            
            offSet = 0;
            
        }else
        {
            offSet = SCREEN_WIDTH;
        }
        
        [self.collectionView setContentOffset:CGPointMake(offSet, 0) animated:YES];
    }];
    
    [self addSubview:self.titleView];
    
    self.searchBtn = [WPReadingSearchBtn btnWithImageName:@"main_search" title:@"请输入疾病、医院、医生"];
    [self addSubview:self.searchBtn];
    
    
    UIView *searchBtnLine = [UIView new];
    searchBtnLine.backgroundColor = RGB_SAME(220);
    [self.searchBtn addTarget:self action:@selector(searchBtnDidClick) forControlEvents:UIControlEventTouchDown];
    [self addSubview:searchBtnLine];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    self.collectionView = [[WPReadingCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    
    self.collectionView.pagingEnabled = YES;
    self.collectionView.bounces = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    [self.collectionView registerClass:[WPReadingFirstCollectionViewCell class] forCellWithReuseIdentifier:@"first"];
    [self.collectionView registerClass:[WPReadingSecondCollectionViewCell class] forCellWithReuseIdentifier:@"second"];
   
    [self addSubview:self.collectionView];
    
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(64);
    }];
    
    
    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(30*SCALE);
        make.width.mas_equalTo(SCREEN_WIDTH-20);
        make.centerX.equalTo(self);
        make.top.equalTo(self.titleView.mas_bottom).offset(7*SCALE);
    }];
    
    [searchBtnLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(self.searchBtn.mas_bottom).offset(7*SCALE);
    }];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.top.equalTo(searchBtnLine.mas_bottom);
    }];
}

-(void)searchBtnDidClick
{
    if ([self.delegate respondsToSelector:@selector(WPReadingViewDidClickSearchBtn:)]) {
        
        [self.delegate WPReadingViewDidClickSearchBtn:self];
    }
}


-(void)setSecondCollectionViewCell:(WPReadingSecondCollectionViewCell *)secondCollectionViewCell
{
    _secondCollectionViewCell = secondCollectionViewCell;
    
    [self.delegate collectionViewCellBeCreated:self];
}

@end









